//
//  AllContactVCModel.m
//  safeLady
//
//  Created by Justsoso on 2017/6/9.
//  Copyright © 2017年 xmy. All rights reserved.
//

#import "AllContactVCModel.h"
#import "IMTableViewCell.h"
#import "DXMessageToolBar.h"

@interface AllContactVCModel()

@property (nonatomic,strong) NSMutableArray *sectionArr;
@end


@implementation AllContactVCModel


- (void)initialize
{
    [super initialize];
    
}


- (void)bindTableView:(UITableView *)tableView
{
    [super bindTableView:tableView];
    self.cellReuseIdentifier = @"IMTableViewCell";
    [self.mTableView registerCellWithReuseIdentifier:@"IMTableViewCell"];
    self.shouldMoreToRefresh = YES;
    self.shouldPullToRefresh = YES;
    self.pageSize = @(10);
}

- (RACSignal*)requestRemoteDataSignalWithPage:(NSUInteger)page
{
    RACSignal *fecthSignal = [self.httpService getUserMessagepage:page page_size:self.pageSize.integerValue resultClass:nil];
    
    @weakify(self);
    return [[[fecthSignal collect] doNext:^(id x) {
        NSLog(@"===== x %@",x);
        @strongify(self);
        if ([self.mTableView.mj_footer isRefreshing]) {
            [self.mTableView.mj_footer endRefreshing];
        }
        if ([self.mTableView.mj_header isRefreshing]) {
            [self.mTableView.mj_header endRefreshing];
        }
    }] map:^id(NSArray *responses) {
        NSLog(@"===== value %@",responses);
        @strongify(self);
        BaseModel *model = responses.firstObject;
        
        if (model.code == 200) {
            
//            array=model.data;
//            self.dataSource=@[array];
//            [self.mTableView reloadData];
            NSMutableArray * array = [NSMutableArray arrayWithArray:model.data];
            if([self.curPage intValue] > 1){
                NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithArray:self.dataSource];
                [indexPaths addObjectsFromArray:@[model.data]];
                self.dataSource = indexPaths;
            }else{
                self.dataSource = @[array];
            }
            [self.mTableView reloadData];
        }else{
            
        }
//        return array;
//        return nil;
        return [RACSignal empty];
        
    }];
}

- (void)configureCell:(IMTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{

    cell.name.text = object[@"nikename"];
    cell.phone.text = object[@"mobile"];
    [cell.img setImageWithURLString:object[@"img_top"] placeholderImage:[UIImage imageNamed:@"nil"]];
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    DXMessageToolBar *dxMessageToolBar = [[DXMessageToolBar alloc] init];
//    [self.viewController pushViewController:dxMessageToolBar animated:YES];
//}
@end
